package cn.edu.java.thread.原子类;

import java.util.concurrent.atomic.DoubleAdder;

public class DoubleAdderDemo {
    public static void main(String[] args) throws InterruptedException {
        // 创建DoubleAdder对象
        DoubleAdder doubleAdder = new DoubleAdder();

        // 创建多个线程进行累加操作
        Thread[] threads = new Thread[10];
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread(() -> {
                // 执行累加操作
                doubleAdder.add(1.5);
            });
        }

        // 启动线程
        for (Thread thread : threads) {
            thread.start();
        }

        // 等待所有线程执行完毕
        for (Thread thread : threads) {
            thread.join();
        }

        // 获取累加结果
        double sum = doubleAdder.sum();
        System.out.println("累加结果：" + sum);
    }
}

